package backend.attribute.manager;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import core.attribute.model.AttributeSet;
import core.util.HibernateCoreUtil;

public class AttributeSetManager extends HibernateCoreUtil
{
	public List<AttributeSet> getAttributeSetList()
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List <AttributeSet> attributeSet = session.createQuery("from AttributeSet").list();	
		session.getTransaction().commit();
		return attributeSet ;
	}
	public void saveAttributeSet(AttributeSet as)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.saveOrUpdate(as);
		session.getTransaction().commit();
	}
	public AttributeSet getAttributeSetByName(String name)
	{
		AttributeSet as = null ;
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		as = (AttributeSet) session.createCriteria(AttributeSet.class).add(Restrictions.eq("name", name)).uniqueResult();
		session.getTransaction().commit();
		return as;
	}
	public void deleteAttributeSet(AttributeSet as)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(as);
		session.getTransaction().commit();
	}
	public AttributeSet getAttributeSetByUuid(Long uuid)
	{
		AttributeSet as = null ;
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		as = (AttributeSet) session.get(AttributeSet.class, uuid);
		session.getTransaction().commit();
		return as ;
	}

}
